package edu.zju.jzs.firstsort.entity;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created by 11544 on 2017/10/12.
 */
public class FlowBean implements WritableComparable<FlowBean> {
    private long upflow;
    private long downflow;
    private long sumflow;

    public FlowBean()
    {

    }

    public FlowBean(Long upflow,Long downflow)
    {
        super();
        this.setUpflow(upflow);
        this.setDownflow(downflow);
        this.setSumflow(upflow+downflow);
    }


    public int compareTo(FlowBean o) {
        if (o instanceof FlowBean)
            return -1;
        return this.getSumflow()>o.getSumflow()?1:this.getSumflow()==o.getSumflow()?0:this.getUpflow()>o.getUpflow()?1:this.getUpflow()==o.getUpflow()?0:1;

    }

    public void readFields(DataInput in) throws IOException {
        this.setUpflow(in.readLong());
        this.setDownflow(in.readLong());
        this.setSumflow(in.readLong());
    }

    public void write(DataOutput out) throws IOException {
        out.writeLong(this.getUpflow());
        out.writeLong(this.getDownflow());
        out.writeLong(this.getSumflow());
    }


    @Override
    public String toString() {
        return "FlowBean{" +
                "upflow=" + upflow +
                ", downflow=" + downflow +
                ", sumflow=" + sumflow +
                '}';
    }

    public long getUpflow() {
        return upflow;
    }

    public void setUpflow(long upflow) {
        this.upflow = upflow;
    }

    public long getDownflow() {
        return downflow;
    }

    public void setDownflow(long downflow) {
        this.downflow = downflow;
    }

    public long getSumflow() {
        return sumflow;
    }

    public void setSumflow(long sumflow) {
        this.sumflow = sumflow;
    }
}
